package td.pt.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.Widget;

public class UsabilityScaleQuestion extends Composite implements HasText {

	private static UiBinderCompositeUiBinder uiBinder = GWT
			.create(UiBinderCompositeUiBinder.class);

	interface UiBinderCompositeUiBinder extends
			UiBinder<Widget, UsabilityScaleQuestion> {
	}

	public UsabilityScaleQuestion() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	@UiField
	Label description;
	@UiField
	RadioButton veryEasy;
	@UiField
	RadioButton easy;
	@UiField
	RadioButton average;
	@UiField
	RadioButton hard;
	@UiField
	RadioButton veryHard;

	Integer value = 0;

	public UsabilityScaleQuestion(String questionText) {
		initWidget(uiBinder.createAndBindUi(this));
		description.setText(questionText);
	}

	@UiHandler("veryEasy")
	void onVeryEasyClick(ClickEvent e) {
		value = 5;
	}

	@UiHandler("easy")
	void onEasyClick(ClickEvent e) {
		value = 4;
	}

	@UiHandler("average")
	void onAverageClick(ClickEvent e) {
		value = 3;
	}

	@UiHandler("hard")
	void onHardClick(ClickEvent e) {
		value = 2;
	}

	@UiHandler("veryHard")
	void onVeryHardClick(ClickEvent e) {
		value = 1;
	}

	public void setText(String text) {
		description.setText(text);
	}

	public String getText() {
		return description.getText();
	}

	public Integer getValue() {
		return value;
	}

	public void setControlName(String name) {
		veryEasy.setName(name);
		easy.setName(name);
		average.setName(name);
		hard.setName(name);
		veryHard.setName(name);
	}
}
